/// 今日信息模型 - Today info model
/// 
/// 用于存储首页显示的今日信息数据
/// Used to store today's information data displayed on the home page
class TodayInfo {
  final String solarDate;
  final String lunarDate;
  final String weekday;
  final String constellation;
  final String chineseZodiac;
  final String ganZhi;
  final String? solarTerm;
  final List<String> festivals;
  final List<String> lunarFestivals;
  final List<String> suitable;
  final List<String> avoid;
  final String fiveElements;
  final String nayin;
  // 运势相关属性 - Fortune related properties
  final int fortuneScore;
  final int luckyNumber;
  final String luckyColor;
  final String luckyDirection;
  final String suggestion;
  final String warning;
  final String auspiciousTime;

  const TodayInfo({
    required this.solarDate,
    required this.lunarDate,
    required this.weekday,
    required this.constellation,
    required this.chineseZodiac,
    required this.ganZhi,
    this.solarTerm,
    this.festivals = const [],
    this.lunarFestivals = const [],
    this.suitable = const [],
    this.avoid = const [],
    required this.fiveElements,
    required this.nayin,
    this.fortuneScore = 75,
    this.luckyNumber = 8,
    this.luckyColor = '紫色',
    this.luckyDirection = '东方',
    this.suggestion = '今日宜保持积极心态',
    this.warning = '',
    this.auspiciousTime = '09:00-11:00',
  });

  /// 从JSON创建实例 - Create instance from JSON
  factory TodayInfo.fromJson(Map<String, dynamic> json) {
    return TodayInfo(
      solarDate: json['solar_date'] ?? '',
      lunarDate: json['lunar_date'] ?? '',
      weekday: json['weekday'] ?? '',
      constellation: json['constellation'] ?? '',
      chineseZodiac: json['chinese_zodiac'] ?? '',
      ganZhi: json['gan_zhi'] ?? '',
      solarTerm: json['solar_term'],
      festivals: List<String>.from(json['festivals'] ?? []),
      lunarFestivals: List<String>.from(json['lunar_festivals'] ?? []),
      suitable: List<String>.from(json['suitable'] ?? []),
      avoid: List<String>.from(json['avoid'] ?? []),
      fiveElements: json['five_elements'] ?? '',
      nayin: json['nayin'] ?? '',
      fortuneScore: json['fortune_score'] ?? 75,
      luckyNumber: json['lucky_number'] ?? 8,
      luckyColor: json['lucky_color'] ?? '紫色',
      luckyDirection: json['lucky_direction'] ?? '东方',
      suggestion: json['suggestion'] ?? '今日宜保持积极心态',
      warning: json['warning'] ?? '',
      auspiciousTime: json['auspicious_time'] ?? '09:00-11:00',
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'solar_date': solarDate,
      'lunar_date': lunarDate,
      'weekday': weekday,
      'constellation': constellation,
      'chinese_zodiac': chineseZodiac,
      'gan_zhi': ganZhi,
      'solar_term': solarTerm,
      'festivals': festivals,
      'lunar_festivals': lunarFestivals,
      'suitable': suitable,
      'avoid': avoid,
      'five_elements': fiveElements,
      'nayin': nayin,
      'fortune_score': fortuneScore,
      'lucky_number': luckyNumber,
      'lucky_color': luckyColor,
      'lucky_direction': luckyDirection,
      'suggestion': suggestion,
      'warning': warning,
      'auspicious_time': auspiciousTime,
    };
  }

  /// 是否有节日 - Has festivals
  bool get hasFestivals => festivals.isNotEmpty || lunarFestivals.isNotEmpty;

  /// 是否有节气 - Has solar term
  bool get hasSolarTerm => solarTerm != null && solarTerm!.isNotEmpty;

  /// 所有节日 - All festivals
  List<String> get allFestivals => [...festivals, ...lunarFestivals];

  /// 宜事文本 - Suitable text
  String get suitableText => suitable.isEmpty ? '无' : suitable.join('、');

  /// 忌事文本 - Avoid text
  String get avoidText => avoid.isEmpty ? '无' : avoid.join('、');
}

/// 运势项目模型 - Fortune item model
class FortuneItem {
  final String title;
  final String description;
  final String iconPath;
  final String color;
  final double score;

  const FortuneItem({
    required this.title,
    required this.description,
    required this.iconPath,
    required this.color,
    required this.score,
  });

  /// 从JSON创建实例 - Create instance from JSON
  factory FortuneItem.fromJson(Map<String, dynamic> json) {
    return FortuneItem(
      title: json['title'] ?? '',
      description: json['description'] ?? '',
      iconPath: json['icon_path'] ?? '',
      color: json['color'] ?? '',
      score: (json['score'] ?? 0.0).toDouble(),
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'title': title,
      'description': description,
      'icon_path': iconPath,
      'color': color,
      'score': score,
    };
  }
}

/// 功能项目模型 - Feature item model
class FeatureItem {
  final String title;
  final String description;
  final String route;
  // 类型用于决定颜色和图标 - Type determines color and icon
  final String type;
  // 颜色字符串（如 #8B5CF6） - Color hex string
  final String color;
  // 可选的图标路径（不强制使用） - Optional icon path
  final String iconPath;

  const FeatureItem({
    required this.title,
    required this.description,
    required this.route,
    required this.type,
    required this.color,
    this.iconPath = '',
  });

  /// 从JSON创建实例 - Create instance from JSON
  factory FeatureItem.fromJson(Map<String, dynamic> json) {
    return FeatureItem(
      title: json['title'] ?? '',
      description: json['description'] ?? '',
      route: json['route'] ?? '',
      type: json['type'] ?? '',
      color: json['color'] ?? '',
      iconPath: json['icon_path'] ?? '',
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'title': title,
      'description': description,
      'route': route,
      'type': type,
      'color': color,
      'icon_path': iconPath,
    };
  }
}